<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>canvas</title>
	<style>
	#can {
		border:1px solid #ccc;
	}
	#div {
		display: inline-block;
		width:300px;
		height:200px;
		border:2px dashed #000;
	}
	</style>
</head>
<body>
	<canvas id="can">
		
	</canvas>
	<div id="div"></div>
	<script>

		function drawCanvas() {

			// 获取到canvas的元素,context是上下文
			var canvas = document.getElementById('can'),
				context = canvas.getContext('2d');

			// 保存当前绘图状态
			context.save();

			// 向右下方移动绘图上下文
			context.translate(70, 140);

			// 以原点为起点，绘制与前面相同的线段
			context.beginPath();
			context.moveTo(0, 0);
			context.lineTo(70, -70);
			context.stroke();

			// 恢复到原有状态
			context.restore();
		}

		window.addEventListener('load', drawCanvas, true);
	</script>
</body>
</html>